package com.example.wyc.mybiye1;

import android.content.pm.ActivityInfo;
import android.graphics.Point;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.example.wyc.mybiye.R;
import com.example.wyc.mybiye1.lei.guangMingLei;
import com.example.wyc.mybiye1.sql.MYSQL;
import com.goach.widget.BrokenLineView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class CanvasActivity extends AppCompatActivity {
    BrokenLineView brokenView;

    MYSQL mysql;
    guangMingLei gmLei;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_canvas);
        mysql=new MYSQL(this);
        brokenView=findViewById(R.id.brokenView);
        initView();
        bbrokenView();
    }
//    List<String> GMs=new ArrayList<>();
    List<String> Y轴=new ArrayList<>();
    List<String> X轴=new ArrayList<>();
    public void initView(){
        //gmLei=new guangMingLei();
//        GMs.add("1000");
//        GMs.add("2000");
//        GMs.add("3000");
//        GMs.add("4000");
//        GMs.add("5000");
        Y轴.add("20℃");
        Y轴.add("40℃");
        Y轴.add("60℃");
        Y轴.add("80℃");
        Y轴.add("100℃");
        X轴.add("0");
//        X轴.add("2016/10/1");
//        X轴.add("2016/10/2");
//        X轴.add("2016/10/3");
//        X轴.add("2016/10/4");
//        X轴.add("2016/10/5");
        //--
       gmLei=mysql.chaXunGuangMing2();

    }

    public void bbrokenView(){
        brokenView.setXUnitValue(1)
                .setYUnitValue(20)
                .setXTextUnits(jiSuanXX())
                .setYTextUnits(Y轴)
                .setDateList(jiSuanHE())
                .startDraw();
//Arrays.asList("0","2016/10/1","2016/10/2","2016/10/3","2016/10/4","2016/10/5")
//        brokenView.setXUnitValue(1)
//                .setYUnitValue(20)
//                .setXTextUnits(X轴)
//                .setYTextUnits(Y轴)
//                .setDateList(Arrays.asList(new Point(1,20),new Point(2,30),new Point(3,40),new Point(4,70),new Point(5,80)))
//                .startDraw();
    }
//
    public List<Point> jiSuanHE(){
        List<Point> list=new ArrayList<>();
        for (int i=0;i<gmLei.Gms.size();i++){
            int j= Integer.parseInt(gmLei.Gms.get(i));
            list.add(new Point(i+1,j));
        }
        return list;
    }
//    //计算X轴
    public List<String> jiSuanXX(){
        for (int i=0;i<gmLei.times.size();i++){
            X轴.add(gmLei.times.get(i));
        }
        return X轴;
    }

    //源码
//            brokenView.setXUnitValue(1)
//                    .setYUnitValue(2000)
//                .setXTextUnits(Arrays.asList("0","1","2","3","4","5","6","7","8","9","10"))
//            .setYTextUnits(Arrays.asList("2000元","4000元","6000元","8000元","10000元"))
//            .setDateList(Arrays.asList(new Point(1,1000), new Point(2,2000), new Point(3,3000)
//                        , new Point(4,4000), new Point(5,5000), new Point(6,6000),new Point(7,5000),new Point(8,4000),
//                        new Point(9,3000),new Point(10,2000)))
//            .startDraw();
}
